let app = new Vue({
    el:'#app',
    data:{
        goods:[
            {id:1,name:'iphone12',time:new Date()},
            {id:2,name:'iphone11',time:new Date()},
            {id:3,name:'iphone8',time:new Date()},
            {id:4,name:'iphoneX',time:new Date()},
            {id:5,name:'iphone6',time:new Date()}
        ],
        goodID:null,
        goodName:null,
        key:''
    },
    methods:{
        add(){
            let id = this.goods[this.goods.length-1].id+1
            this.goods.push({
                id:id,
                name:this.goodName,
                time:new Date()
            })
            // 添加成功后 清空name值
            this.goodName = null
        },
        remove(index){
            this.goods.splice(index,1)
        }
    },
    filters:{
        dateFormat(date){
            let dateObj = new Date(date)
            let fullYear = dateObj.getFullYear()
            let month = (dateObj.getMonth()+1).toString().padStart(2,0)
            let day = dateObj.getDate().toString().padStart(2,0)
            let hour = dateObj.getHours().toString().padStart(2,0)
            let minute = dateObj.getMinutes().toString().padStart(2,0)
            let seconds = dateObj.getSeconds().toString().padStart(2,0)

            return `${fullYear}-${month}-${day} ${hour}:${minute}:${seconds}`
        }
    },
    computed:{
        search(){
            return this.goods.filter((item)=>{
                return item.name.includes(this.key)
            })
        }
    }
})